<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="12">
          <a-col :md="6" :sm="8">
            <a-form-item
              label="日期范围"
              :maxLength="50">
              <a-range-picker @change="onChange" v-model="queryParam.timeinfo" format="YYYY-MM-DD"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)" icon="search">查询</a-button>
              <a-button
                @click="() => {this.$objToReset(queryParam),this.depart=undefined,$refs.table.refresh(true)}"
                icon="reload"
                style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
      <div class="table-operator">
        <a-button
          @click="exportExcel()"
          type="primary"
          style="margin-bottom: 10px"
          icon="download"
        >导出</a-button>
      </div>
      <s-table
        ref="table"
        rowKey="id"
        size="small"
        :scroll="{ x: 1500 }"
        pageSize="100"
        :columns="columns"
        :alert="options.alert"
        :data="loadData">
        <template slot="action" slot-scope="text, record">
          <a @click="handelView(record)" >
            <a-icon />查看</a>
        </template>
      </s-table>

    </div>
    <div class="home-line-box">
      <div class="home-line-top">
        <div class="home-title">数据分析图</div>
      </div>
      <div class="home-line-content" ref="myOneChart"></div>
    </div>
  </a-card>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import { deleteAction, fileAction, postAction } from '@/api/manage'
  import { mixin } from '@/utils/mixin'
  import * as echarts from 'echarts'

  export default {
    name: 'HosWorksList',
    mixins: [mixin],
    components: { STable, Ellipsis },
    data () {
      return {
        visible: false,
        typeName: '',
        // 查询条件
        queryParam: {
          title: '',
          times: '',
          number: '',
          state: 1
        },
          totals:0,
        // 表头
        // 如果需要字典，那么需要在columns列中加入 customRender: (text) => this.$sysDictFilter(text, 'xxxx')xxxx 为dataIndex
        columns: [
          {
            title: '学校',
            dataIndex: 'schname'
          },
          {
            title: '学生数',
            dataIndex: 'studentnum'
          },
          {
            title: '已检',
            dataIndex: 'yjnum'
          },
            {
                title: '未检',
                dataIndex: 'vjnum'
            },
            {
                title: '漏项',
                dataIndex: 'lxnum'
            },
         /* {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }*/
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          var that = this
          console.log('loadData.parameter', parameter)
          return postAction(this.url.list, Object.assign(parameter, this.queryParam))
              .then(res => {
                  this.initOneChart(res.result.data1)
                return res.result
              })
        },
        selectedRowKeys: [],
        options: {
          alert: {
            clear: () => {
              this.selectedRowKeys = []
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'checkbox'
          }
        },
        url: {
          list: '/system/eyeStudentTestRecord/countList',
          listcountExcel: '/system/eyeStudentTestRecord/countListExcel',
        },
        depart: undefined,
        deptList: []
      }
    },
    computed: {},
    mounted () {

    },
    methods: {
        // 初始化数据分析
        initOneChart(data) {
            // 请求类型 日月天
            const params = {
                type: this.oneType
            }
            console.log(data)
            // 发起请求获取数据
            // const data = {
            //     dates: ['3.12', '3.13', '3.14', '3.15', '3.16', '3.17', '3.18', '3.19', '3.20', '3.21', '3.22', '3.23'],
            //     notOrders: [1500, 1800, 2100, 3800, 1200, 4000, 5700, 1800, 1220, 2800, 7100, 1120],
            //     orders: [6000, 7000, 2000, 1000, 1200, 1500, 2000, 1800, 9000, 6200, 1500, 1000],
            //     allOrders: [7500, 7800, 4100, 4800, 2400, 5500, 7700, 3600, 11220, 8800, 8600, 2120]
            // }
            const myChart = echarts.init(this.$refs.myOneChart)
            const option = {
                grid: {
                    top: '7%',
                    left: '5%',
                    right: '2%',
                    bottom: '10%'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'line',
                        lineStyle: {
                            color: '#3399FF',
                            type: 'solid'
                        }
                    },
                    backgroundColor: 'rgba(66, 161, 255, 0.9)',
                    borderWidth: 0,
                    textStyle: {
                        color: '#ffffff'
                    }
                },
                xAxis: {
                    data: data.schnames
                },
                yAxis: {
                    type: 'value',
                    min: 0
                },
                series: [
                    {
                        name: '学生数',
                        type: 'line',
                        showSymbol: false,
                        smooth: true,
                        areaStyle: {
                            origin: 'auto',
                            opacity: 0.1
                        },
                        itemStyle: {
                            color: '#42A1FF'
                        },
                        data: data.studentnums
                    },
                    {
                        name: '已检',
                        type: 'bar',
                        data: data.yjnum,
                        barWidth:'30px',
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                { offset: 0, color: '#3399FF' },
                                { offset: 1, color: '#73C5FF' }
                            ]),
                            borderRadius: [150, 150, 0, 0]
                        },

                    },
                    {
                        name: '未检',
                        type: 'bar',
                        data: data.vjnum,
                        barWidth:'30px',
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                { offset: 0, color: '#68cfff' },
                                { offset: 1, color: '#52ffc3' }
                            ]),
                            borderRadius: [150, 150, 0, 0]
                        },

                    },
                    {
                        name: '漏项',
                        type: 'bar',
                        data: data.lxnum,
                        barWidth:'30px',
                        itemStyle: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                { offset: 0, color: '#446cff' },
                                { offset: 1, color: '#7671ff' }
                            ]),
                            borderRadius: [150, 150, 0, 0]
                        },

                    },
                ]
            }
            myChart.setOption(option)
        },
      searchQuery () {
        this.$refs.table.refresh(true)
      },
      getDeptList () {
        postAction(this.url.getDeptList, {})
            .then(res => {
              this.deptList = res.result.data
            })
      },
      selectdept () {
        this.queryParam.depart = this.depart.join(',')
      },
      // 保存刷新
      modalEditOk () {
        this.$refs.table.refresh()
      },
      // 查看
      handelView (record) {
        this.$refs.modalView.show(record,this.queryParam)
      },
      onChange (value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.times = dateString[0] + '~' + dateString[1]
      },
      exportExcel () {
        fileAction(this.url.listcountExcel, Object.assign(this.queryParam))
            .then(res => {
              console.log(this.data1)
            })
      },
      exportExcelPatient () {
        fileAction(this.url.listcountExcelPatient, Object.assign(this.queryParam))
            .then(res => {
              console.log(this.data1)
            })
      },
      // 开启选择
      onSelectChange (selectedRowKeys) {
         console.log('selectedRowKeys changed: ', selectedRowKeys)
         this.selectedRowKeys = selectedRowKeys
      }
    },
    watch: {}
  }
</script>
<style scoped>
  .home-line-box {
    min-height: 306px;
    background-color: #ffffff;
    padding: 20px;
    border-radius: 10px;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
  }

  .home-line-content {
    flex: 1;
  }

  .home-line-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
  }

  .home-line-top-type div {
    flex: 1;
    text-align: center;
    line-height: 25px;
    cursor: pointer;
  }

  .home-line-top-type div.select {
    color: #1890ff;
  }
  .home-line-top-type div:nth-child(2) {
    border-left: 1px solid #ebeff5;
    border-right: 1px solid #ebeff5;
  }


</style>
